package com.example.anliku.controller;

import com.example.anliku.entity.Comment;
import com.example.anliku.entity.ExampleComment;
import com.example.anliku.entity.Message;
import com.example.anliku.mapper.ExampleCommentMapper;
import com.example.anliku.service.CommentService;
import com.example.anliku.service.ExampleCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Api(tags = "评论模块")
@RestController
@RequestMapping("/api/comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    @Resource
    private ExampleCommentService exampleCommentService;

    @ApiOperation(value = "添加评论")
    @PostMapping("/one")
    public Message insert(Comment comment) {
        comment.setCommentState(0);
        comment.setCommentTime(new Date());
        return commentService.insertSelective(comment);
    }

    @ApiOperation(value = "添加评论案例对应关系")
    @PostMapping("/oneone")
    public Message insertone(ExampleComment exampleComment) {
        return exampleCommentService.insertSelective(exampleComment);
    }

    @ApiOperation(value = "根据案例Id查找此案例全部评论")
    @GetMapping("/selectAllComment")
    public Message selectAllexampleComment(Integer exampleId) {
        return exampleCommentService.selectAllByExampleCommentExampleId(exampleId);
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("/delete")
    public Message delete(Integer commentId,@RequestParam Integer exampleId) {
        return commentService.deleteByPrimaryKey(commentId,exampleId);
    }

    @ApiOperation(value = "修改评论")
    @PostMapping("/put")
    public Message update(Comment comment) {
        return commentService.updateByPrimaryKeySelective(comment);
    }

    @ApiOperation(value = "获取所有评论")
    @GetMapping("/all")
    public Message selectAll(){
        return commentService.selectAll();
    }

    @ApiOperation(value = "根据评论id获取评论")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer commentId){
        return commentService.selectByPrimaryKey(commentId);
    }

    @ApiOperation(value="修改评论当前审核状态")
    @PostMapping("/update")
    public Message updateByCommentIdAndCommentState(int commentId,int commentState,String commentCheckId){
        return commentService.updateByCommentIdAndCommentState(commentId,commentState,commentCheckId);
    }

}
